#ifndef _BOOT_H_
#define _BOOT_H_
#include <stdint.h>
#include <stdbool.h>
#include <string.h>

#define BOOT_FLASH_BASE			0x08000000
#define BOOT_FLASH_PAGE_SIZE	(1024*4)

typedef void (*appJump)(void);

#pragma pack(1)
typedef struct {
	uint32_t msp;			//主栈地址
	uint32_t reset_handler;	//复位地址
}image_head_t;
#pragma pack()

void boot_init(void);
void boot_uart_send(uint8_t *buf, uint32_t len);
void boot_ble_send(uint8_t *buf, uint32_t len);
int boot_app_check(uint32_t app_addr);
void boot_run_app(uint32_t app_addr);
uint32_t boot_flash_erase(uint32_t addr, uint32_t total);
void boot_flash_read(uint32_t addr, uint8_t *bytes, uint16_t size);
void boot_flash_read_with_icache(uint32_t addr, uint8_t *bytes, uint16_t size);
void boot_flash_write(uint32_t addr, uint32_t *bytes, uint32_t size);
int boot_flash_verify(uint32_t addr, void *bytes, uint32_t size);
uint32_t boot_flash_calc_enc_sum(uint32_t addr_start, uint32_t addr_end);

int boot_flash_write_data(uint32_t address, uint8_t data[], uint32_t length);
int boot_flash_sync(void);

uint32_t boot_flash_size(void);
uint32_t boot_get_uid(void);
int boot_check_image(const image_head_t* image_head);

#endif
